@model Gman.WebApp.Models.PersonalModel

    
<style>
    .ui-widget
    {
        font-size: 0.8em;
    }
    .ui-dialog .ui-dialog-content
    {
        padding:0px;
    }
</style>

@{
    string PopupGUID = Guid.NewGuid().ToString();
}

<div id="PersonalPopup_@(PopupGUID)" >
    <div>
        <div>
            <div class="DataTable">
                <fieldset>    
                    <table  width="100%">       
                        <tr>
                            <td>
                                <div class="editor-label">
                                    Nombres
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.NomsPers, new { style = "width: 90%;", propertyname = "Personal.NomsPers" }))</div>
                            </td>
                            <td>
                                <div class="editor-label">
                                    Apellidos
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.ApePers, new { style = "width: 90%;", propertyname = "Personal.ApePers" }))</div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="editor-label">
                                    Nro Documento
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.NroDocuPers, new { style = "width: 90%;", propertyname = "Personal.NroDocuPers" }))</div>
                            </td>
                            <td>
                                <div class="editor-label">
                                    Cargo
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.CargoPers, new { style = "width: 90%;", propertyname = "Personal.CargoPers" }))
                                </div>
                            </td>
                        </tr>
                        <tr>            
                            <td>
                                <div class="editor-label">
                                    Tipo/Categoria
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.TipoPers, new { style = "width: 90%;", propertyname = "Personal.TipoPers" }))</div>
                            </td>
                            <td>
                                <div class="editor-label">
                                    Area
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.AreaPers, new { style = "width: 90%;", propertyname = "Personal.AreaPers" }))</div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="editor-label">
                                    Fecha Ingreso
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.FecIngrPers, new { @class = "date", id = "FecNac", style = "width: 80px;", propertyname = "Personal.FecIngrPers" }))
                                </div>
                            </td>
                            <td>
                                <div class="editor-label">
                                    Jefe Inmediato
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.JefeInmePers, new { style = "width: 90%;", propertyname = "Personal.JefeInmePers" }))
                                </div>
                            </td>            
                        </tr>
                        <tr>
                            <td>
                                <div class="editor-label">
                                    Email
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.EmailPers, new { style = "width: 90%;", propertyname = "Personal.EmailPers" }))
                                </div>
                            </td>
                            <td>
                                <div class="editor-label">
                                    Telefono
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.NroTelfPers, new { style = "width: 90%;", propertyname = "Personal.NroTelfPers" }))
                                </div>
                            </td>
                        </tr>
                        <tr>            
                            <td>
                                <div class="editor-label">
                                    Celular
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.NroCeluPers1, new { style = "width: 90%;", propertyname = "Personal.NroCeluPers1" }))
                                </div>
                            </td>
                            <td>
                                <div class="editor-label">
                                    RPC
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.NroCeluPers2, new { style = "width: 90%;", propertyname = "Personal.NroCeluPers2" }))
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="editor-label">
                                    RPM
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.NroCeluPers3, new { style = "width: 90%;", propertyname = "Personal.NroCeluPers3" }))
                                </div>
                            </td>
                            <td>
                                <div class="editor-label">
                                    Nextel
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.TextBoxFor(model => model.Personal.NroCeluPers4, new { style = "width: 90%;", propertyname = "Personal.NroCeluPers4" }))
                                </div>
                            </td>            
                        </tr>
                        <tr>
                            <td>
                                <div class="editor-label">
                                    Estado
                                </div>
                            </td>
                            <td>
                                <div>
                                    @(Html.DropDownListFor(model => model.Personal.EstadoPers, Model.Estado, new { style = "width: 90%;", propertyname = "Personal.EstadoPers" }))
                                </div>
                            </td>
                            <td>
                            </td>
                            <td>
                            </td>
                        </tr>                       
                    </table>    
                </fieldset>                
            </div>
        </div>
    </div>     
</div>
   
<script type="text/javascript">

    var personalGuid = "@Model.ID.ToString()";
    var action = "@Model.Action.ToString()";

    $(document).ready(function() {
        setTimeout(function() {
            AddValidatorsDialog();
            SetValidationPersonal();
        }, 500);

        $("[id^='Personal_']").change(function() { UpdateFieldPersonal(this); });
        $(".date").datepicker();
        $(".date").change(function() { parseAndSetDt(this); });
        
        SetupDialog();
    });

    function SetupDialog() {
        var popupTitle = '@((Model.Action.ToString() == "edit") ? "Edición de Personal" : "Nuevo Personal")';

        $("#PersonalPopup_@(PopupGUID)").dialog({
            modal: true,
            resizable: false,
            title: popupTitle,
            width: 800,
            height: 'auto',
            autoOpen: true,
            buttons:
            {
                "Grabar": function() { SavePersonal(); },
                "Cerrar": function() { $(this).dialog("close"); }

            },
            close: function(event, ui) {
                $(this).dialog("destroy");
                $("#PersonalPopupDiv").empty();
            }
        });

        $("#PersonalPopup_@(PopupGUID)").dialog("open");
    }
    
    function SavePersonal() {
        if ($('.ui-dialog img.validation:visible').length) {
            apprise('Por favor corregir todos los errores de validación.');
            return false;
        }
        AddOrEditPersonal(action);
        $("#PersonalPopup_@(PopupGUID)").dialog("close");       
    }

    function SetValidationPersonal() {
        var data =
        {
            id: personalGuid
        };
        $.ajax({
            type: "POST",
            url: window.GetControllerUrl("GetValidation", "Personal"),
            dataType: "json",
            data: data,
            success: function(validationList) {              
                window.UpdateValidationDialog(validationList.PropertyValidationList);
            }
        });
    }

    function UpdateFieldPersonal(element) {
        var that = this;
        var data = getPropertyValuePairWithFormat(element, personalGuid);
        $.ajax({
            type: "POST",
            async: true,
            url: window.GetControllerUrl("UpdateField", "Personal"),
            dataType: "json",
            data: data,
            success: function(result) {
                UpdatePropertiesAndValidationDialog(result);
            },
            error: function() {
                alert("An unexpected error occurred while updating the field, please refresh the page and try again");
            }
        });
    };

    function parseAndSetDt(element) {
        try {
            var dt = $.datepicker.parseDate("dd/mm/yy", $(element).val());
            $(element).datepicker("setDate", dt);
        }
        catch (e) {
            $(element).datepicker("setDate", null);
        }
        window.UpdateFieldPersonal(element);
    }  
    
</script>